package com.lq.schoolshop.config;

import com.lq.schoolshop.Interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author
 * @Date2021/1/6 14:59
 * @Version V1.0
 * 拦截器配置
 **/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedHeaders("*")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")
                .allowCredentials(true).maxAge(3600*3600);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截前台的登录
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/before/**","/main/**","/productdetail/**","/orderlist/**","/wall/**");
        //拦截music的接口
        //registry.addInterceptor(tokenInterceptor).addPathPatterns("/music/**"); orderlist  main productdetail  wall
    }



}
